﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace intelliSys.Management.Automation.Profiler
{
    class OfflineTask
    {
        private static OfflineTaskType tsk = OfflineTaskType._Unspecified_;
        public static bool Contains(OfflineTaskType ott)
        {
            return (tsk | ott) == tsk;
        }
        public static void ExecuteAll()
        {
            ProcessStartInfo psi = new ProcessStartInfo("intelliSys.Test.Automation.RR.exe");
            var argument = new StringBuilder();
            if ((tsk | OfflineTaskType.Update) == tsk)
            {
                argument.Append("|update");
            }
            if ((tsk | OfflineTaskType.DBMigration) == tsk)
            {
                argument.Append("|dbmigration");
            }
            psi.Arguments = argument.ToString();
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                psi.Verb = "runas";
            }
            if (tsk != OfflineTaskType._Unspecified_)
                Process.Start(psi);
        }
        public static void AddOfflineTask(OfflineTaskType taskType)
        {
            tsk = tsk | taskType;
        }
        [Flags]
        public enum OfflineTaskType : uint
        {
            _Unspecified_ = 0,
            /// <summary>
            /// Update is NOT accumulative
            /// </summary>
            Update = 1,
            /// <summary>
            /// DB Migration is NOT accumulative
            /// </summary>
            DBMigration = 2,
        }
    }
}
